package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result queryStudents(String name, Integer degree, Integer clazzId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<Student> Studentlist = studentService.queryStudents(name, degree, clazzId, page, pageSize);
        return Result.success(Studentlist);
    }

    @DeleteMapping("/{ids}")
    public Result deleteStudent(@PathVariable List<Integer> ids) {
        studentService.deleteStudent(ids);
        return Result.success();
    }

    @PostMapping
    public Result insertStudent(@RequestBody Student student) {
        studentService.insertStudent(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result queryStudentById(@PathVariable Integer id) {
        Student student = studentService.queryStudentById(id);
        return Result.success(student);
    }

    @PutMapping
    public Result updateStudent(@RequestBody Student student) {
        studentService.updateStudent(student);
        return Result.success();
    }
    @PutMapping("/violation/{id}/{score}")
    public Result updateStudentViolation (@PathVariable Integer id, @PathVariable Short score){
        studentService.updateStudentViolation(id, score);
        return Result.success();
    }
//    @GetMapping("/report/studentDegreeData")
//    public Result queryStudentDegreeData() {
//        List<Map<String, Object>> list = studentService.calcStudentDegreeData();
//        return Result.success(list);
//    }
}
